<template lang="html">
        <div class="login-div-con">
            <div class="col-md-12 log text-center">
                <h1>梦想改造家-登录</h1>
                <p style="color:red;" id="errpass">{{tips}}</p>
            </div>
            <form action="/" name="loginform" class="col-md-12">
                <input type="text" value="1" name="islogin" style="display:none">
                <input type="text" name="username" class="input-text padding-top1"
                       placeholder="登录名" v-model="user.tel">
                <div class="col-md-12" style="height: 30px"></div>
                <input type="password" name="password" class="input-text padding-top1"
                       placeholder="密码" v-model="user.pass">
                <div class="col-md-12" style="height: 50px"></div>
                <div class="col-sm-12 col-xs-12 col-md-12 float-right">
                    <input type="button" id="goindex" name="login"
                           class="login-btn float-right" value="登陆" v-on:click="goLogin">
                    <a href="register" class="float-right">注册</a>
                    <a href="" class="float-right">忘记密码</a>
                </div>
            </form>
        </div>
</template>
<script>
    import static_config from '../../../../tools/config';
    import cook from '../../../../tools/cookies'
    export default{
        data(){
            return{
                user:{
                    tel:'',
                    pass:''
                },
                tips:''
            }
        },
        methods:{
            goLogin:function(){
                var tel = this.user.tel;
                var data = this.user;
                var telReg = /^1[3|4|5|8][0-9]\d{4,8}$/;
                if(!(telReg.test(tel))){
                    this.tips = '用户名不合法'
                }else{
                    this.$http.post('/users/login',data)
                        .then(function(res){
                            if(res.body.login == 1){
                                this.tips = '';
                                cook.setCookie('user',tel);
                                sessionStorage.setItem("user",tel);
                                window.location.href = static_config.option.host;
                            }else if(res.body.login == -1){
                                this.tips = '用户名不存在';
                            }else if(res.body.login == 0){
                                this.tips = '密码错误';
                            }
                        });
                }
            }
        }
    }
</script>
